package com.anyou.mall.partner.service.impl;

import java.util.List;

import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.utils.DateUtils;
import com.anyou.mall.partner.domain.PartnerLavel;
import com.anyou.mall.partner.dto.MyRankDto;
import com.anyou.mall.partner.dto.PartnerRankingDto;
import com.anyou.mall.partner.mapper.PartnerLavelMapper;
import com.anyou.mall.partner.service.IPartnerLavelService;
import com.anyou.mall.partner.vo.PartnerRankingVo;
import com.anyou.mall.parts.domain.PlaPartsClassify;
import com.anyou.mall.parts.mapper.PlaPartsClassifyMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 合伙人等级Service业务层处理
 *
 * @author ruoyi
 * @date 2023-10-10
 */
@Service
public class PartnerLavelServiceImpl implements IPartnerLavelService
{
    @Autowired
    private PartnerLavelMapper partnerLavelMapper;
    @Autowired
    private PlaPartsClassifyMapper plaPartsClassifyMapper;

    /**
     * 查询合伙人等级
     *
     * @param lavelId 合伙人等级主键
     * @return 合伙人等级
     */
    @Override
    public PartnerLavel selectPartnerLavelByLavelId(Long lavelId)
    {
        return partnerLavelMapper.selectPartnerLavelByLavelId(lavelId);
    }

    /**
     * 查询合伙人等级列表
     *
     * @param partnerLavel 合伙人等级
     * @return 合伙人等级
     */
    @Override
    public List<PartnerLavel> selectPartnerLavelList(PartnerLavel partnerLavel)
    {
        return partnerLavelMapper.selectPartnerLavelList(partnerLavel);
    }

    /**
     * 新增合伙人等级
     *
     * @param partnerLavel 合伙人等级
     * @return 结果
     */
    @Override
    public int insertPartnerLavel(PartnerLavel partnerLavel)
    {
        partnerLavel.setCreateTime(DateUtils.getNowDate());
        return partnerLavelMapper.insertPartnerLavel(partnerLavel);
    }

    /**
     * 修改合伙人等级
     *
     * @param partnerLavel 合伙人等级
     * @return 结果
     */
    @Override
    public int updatePartnerLavel(PartnerLavel partnerLavel)
    {
        partnerLavel.setUpdateTime(DateUtils.getNowDate());
        return partnerLavelMapper.updatePartnerLavel(partnerLavel);
    }

    /**
     * 批量删除合伙人等级
     *
     * @param lavelIds 需要删除的合伙人等级主键
     * @return 结果
     */
    @Override
    public int deletePartnerLavelByLavelIds(Long[] lavelIds)
    {
        return partnerLavelMapper.deletePartnerLavelByLavelIds(lavelIds);
    }

    /**
     * 删除合伙人等级信息
     *
     * @param lavelId 合伙人等级主键
     * @return 结果
     */
    @Override
    public int deletePartnerLavelByLavelId(Long lavelId)
    {
        return partnerLavelMapper.deletePartnerLavelByLavelId(lavelId);
    }
    /**
     * 合伙人排名
     * @param param
     * @return
     */
    @Override
    public List<PartnerRankingVo> selectPartnerRankingList(PartnerRankingDto param) {
        return partnerLavelMapper.selectPartnerRankingList(param);
    }
    /**
     * 可用商品分类列表
     * @return
     */
    @Override
    public List<PlaPartsClassify> goodsTypeList() {
        List<PlaPartsClassify> plaPartsClassifies = plaPartsClassifyMapper.selectList(
                new LambdaQueryWrapper<PlaPartsClassify>()
                .eq(PlaPartsClassify::getParentId, 0));
        return plaPartsClassifies;
    }

    /**
     * 我的排名
     * @param carPartShopId
     * @return
     */
    @Override
    public Integer getMyRank(Long carPartShopId) {
        int rank=0;
        if(carPartShopId!=null){
            List<PartnerRankingVo> list = this.selectPartnerRankingList(new PartnerRankingDto());
            for(PartnerRankingVo vo:list){
                rank=rank+1;
                if(carPartShopId.toString().equals(vo.getCarPartsShopId().toString())){
                    break ;
                }

            }
        }
        return rank;
    }
}
